<template>
  <a-card :bordered="false" style="margin-bottom: 10px">
    <BaseInfo :id="personId" />
    <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="false" :loading="loading" :columns="columns"
      :dataSource="pageData" @change="onTableChange" style="margin-top:20px;">
      <template slot="memberType" slot-scope="text">
        <span v-if="text == '1'">组长</span>
        <span v-if="text == '2'">成员</span>
      </template>
      <template slot="gender" slot-scope="text">
        <span v-if="text == '1'">男</span>
        <span v-if="text == '2'">女</span>
      </template>
      <template slot="post" slot-scope="text">
        <span>{{ setTittle(text) }}</span>
      </template>
    </z-table>
  </a-card>
</template>

<script>
import * as groupApi from '@/api/sjsk/groupManage.js'
import BaseInfo from '@/views/sjsk/modules/BaseInfo'
export default {
  components: {
    BaseInfo
  },
  // props:['idQX','typeQX'],
  data() {
    return {
      loading: false,
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          width: 60,
          align: 'center',
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
        },
        {
          title: '成员类型',
          dataIndex: 'memberType',
          align: 'center',
          scopedSlots: { customRender: 'memberType' },
        },
        {
          title: '姓名',
          dataIndex: 'name',
          align: 'center',
        },
        {
          title: '性别',
          dataIndex: 'gender',
          align: 'center',
          scopedSlots: { customRender: 'gender' },
        },
        {
          title: '年龄',
          dataIndex: 'age',
          align: 'center',
        },
        {
          title: '身份证号',
          dataIndex: 'identification',
          align: 'center',
        },
        {
          title: '职务',
          dataIndex: 'post',
          align: 'center',
          scopedSlots: { customRender: 'post' },
        },
        {
          title: '联系方式',
          dataIndex: 'telphone',
          align: 'center',
        }
      ],
      pageFilter: {
        pageNo: 1,
        pageSize: 10,
        id: this.$route.query.id,
        type: this.$route.query.type
      },
      personId: this.$route.query.personId,
      pageData: {},
    }
  },
  // watch:{
  //   idQX:{
  //     handler(a,b){
  //       console.log(this.idQX,this.typeQX)
  //     }
  //   }
  // },
  created() {

  },
  async mounted() {
    this.onQuery()
  },

  methods: {
    onQuery() {
      this.pageFilter.pageNo = 1
      this.refreshTable()
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'pageNo' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      this.refreshTable()
    },
    refreshTable() {
      this.loading = true
      groupApi.viewGroupMembers(this.pageFilter).then((res) => {
        if (res.success) {
          this.pageData = res.result ? res.result : {}
          this.loading = false
        } else {
          this.loading = false
        }
      })
        .catch((e) => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    setTittle(text) {
      return this.$filterDictTextByCache('groupPost', text)  //现在字典中对应的文字，是全局函数
    },
    onDetail(record) {
      this.$refs.detailModalId.show()
    },
    onAdd() {
      this.$refs.addModalId.show()
    },
  },
}
</script>
<style lang="less" scoped>
.btn {
  position: absolute;
  right: 24px;
  top: 50px;
  z-index: 10;
}
</style>
